/**
 * @author Liu Cong
 */

(function(){

/**
 * An AMF Message contains information about the actual individual
 * transaction that is to be performed. It specifies the remote
 * operation that is to be performed; a local (client) operation
 * to be invoked upon success; and, the data to be used in the
 * operation.
 * <p/>
 * This Message structure defines how a local client would
 * invoke a method/operation on a remote server. Additionally,
 * the response from the Server is structured identically.
 *
 */
FireAMF.MessageBody = function(targetUri, responseUri, data){
    this.targetUri = targetUri;
    this.responseUri = responseUri;
    this.data = data;
};

FireAMF.MessageBody.prototype = {
    /**
     * Retrieve target Uri
     * 
     * @return string
     */
    get targetUri() {
        return this._targetUri;
    },

    /**
     * Set target Uri
     * 
     * @param  string targetUri 
     * @return FireAMF.MessageBody
     */
    set targetUri(targetUri) {
        if (undefined === targetUri) {
            targetUri = '';
        }
        this._targetUri = targetUri;
        return this;
    },

    /**
     * Get target Uri
     * 
     * @return string
     */
    get responseUri() {
        return this._responseUri;
    },

    /**
     * Set response Uri
     * 
     * @param  string responseUri 
     * @return FireAMF.MessageBody
     */
    set responseUri(responseUri) {
        if (undefined === responseUri) {
            responseUri = '';
        }
        this._responseUri = responseUri;
        return this;
    },

    /**
     * Retrieve response data
     * 
     * @return string
     */
    get data() {
        return this._data;
    },

    /**
     * Set response data
     * 
     * @param  mixed data 
     * @return FireAMF.MessageBody
     */
    set data(data)
    {
        this._data = data;
        return this;
    },

    /**
     * Set reply method
     * 
     * @param  string methodName 
     * @return FireAMF.MessageBody
     */
    setReplyMethod: function(methodName)
    {
        if (!/^[\/?]/.test(methodName)) {
            this._targetUri = this._targetUri.replace(/(\/*)\s*$/, '/');
        }
        this._targetUri = this._targetUri + methodName;
        return this;
    },

};

})();
